package com.ruoyi.web.controller.system;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.service.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
//
//import com.xiruan.service.ProcedureReportService;
//import com.xiruan.service.ProvideContractDetailsService;
//import com.xiruan.service.ProvideContractService;
//import com.xiruan.service.PurchasingUnitService;
//import com.xiruan.service.SupplierService;
//import com.xiruan.tools.core.mapper.util.Pager;
//import com.xiruan.tools.core.util.DwrJson;

/**
*
*报表Action
*@author 魏江
*版权所有，违者必究
*
*/
@Controller
@RequestMapping(value = "/system/getReportAction")
public class ProcedureReportAction extends BaseController {
	private String prefix = "system/report";
	@Autowired
	private ProcedureReportService procedureReportServiceImpl;
	@Autowired
	private ISysPurchasingunitService purchasingUnitServiceImpl;
	@Autowired
	private ISysSupplierService supplierServiceImpl;
	@Autowired
	private ISysProvidecontractdetailsService provideContractDetailsServiceImpl;
	@Autowired
	private ISysProvidecontractService provideContractServiceImpl;



	/**
	 * 报表首页，全部数据
	 * @param
	 * @return
	 */
	@RequiresPermissions("system:getReportAction:list")
	@RequestMapping(value = "searchAll")
	public String searchAll(ProvideRecord provideRecord, ModelMap mmap){

		startPage();
		int currentPage = 1;
		int pageSize = 20;
		List<List<?>> listAll = procedureReportServiceImpl.searchAll("", "");
		if(listAll.size() > 0 && listAll != null){
			List<ProvideRecord> listDetails = (List<ProvideRecord>) listAll.get(0);
			List<ProvideRecordData> listCountAll = (List<ProvideRecordData>) listAll.get(1);
			
//			Pager pager = new Pager(pageSize,listDetails.size(),currentPage);
//			if(listDetails.size() > pageSize){
//				pager.setDataList(listDetails.subList(0, pageSize));
//			}
//			else{
//				pager.setDataList(listDetails);
//			}

			mmap.put("listDetails", listDetails);
			mmap.put("listCountAll", listCountAll);
		}
		
		return prefix+"/searchAll";
	}
	/**
	 * 供货商供货统计
	 * @param mmap
	 * @return
	 */
	@RequiresPermissions("system:getReportAction:gyslist")
	@RequestMapping(value = "querySupplierRecord")
	public String querySupplierRecord(ModelMap mmap){
		Map<String, Object> condition = new HashMap<String, Object>();

		List<SysProvidecontractdetails> providecontractdetailsList = provideContractDetailsServiceImpl.selectSysProvidecontractdetailsList(null);
		List<SysSupplier> suppliers = supplierServiceImpl.selectSysSupplierList(null);
		/*Pager<ProvideContractDetails> pager = provideContractDetailsServiceImpl.queryPage(condition, 1, 50, null, null);
		condition.put("state", 1);
		List<Supplier> lists = supplierServiceImpl.queryList(condition, null, null);*/
		for(int i = 0;i<providecontractdetailsList.size();i++){
			SysProvidecontract providecontract = provideContractServiceImpl.selectSysProvidecontractById(providecontractdetailsList.get(i).getProvideContractId());
			if(providecontract != null){
				SysSupplier sysSupplier = supplierServiceImpl.selectSysSupplierById(providecontract.getSupplierId());
				SysPurchasingunit purchasingunit = purchasingUnitServiceImpl.selectSysPurchasingunitById(providecontract.getPurchasingUnitId());
				providecontractdetailsList.get(i).setSupplierName(sysSupplier.getSupplierName());
				providecontractdetailsList.get(i).setUnitName(purchasingunit.getUnitName());
				double zhekou = providecontractdetailsList.get(i).getDealPrice()/providecontractdetailsList.get(i).getWinPrice();
				providecontractdetailsList.get(i).setAttribite3(String.valueOf(zhekou*100));
			}

		}
		mmap.put("lists", providecontractdetailsList);
		mmap.put("suppliers", suppliers);
		return prefix+"/supplierRecord";
	}

	/**
	 * 分类统计查询

	 * @return
	 */
	@RequiresPermissions("system:getReportAction:fllist")
	@RequestMapping(value = "queryClassificationGoodsRecord")
	public String queryClassificationGoodsRecord(ProvideRecord provideRecord,ModelMap mmap){

		List list = procedureReportServiceImpl.queryClassificationGoodsRecord(provideRecord);

		if(list.size()<=1){
			List list2 = new ArrayList();
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("sumNumber", 0);
			map.put("sumAmount", 0);
			list2.add(map);
			mmap.put("listCountAll", list2);

		}else{
			// 数据的汇总（总采购预算，总采购金额）
			List<ProvideRecord> list2 = procedureReportServiceImpl.sumClassificationGoodsRecord(provideRecord);
			mmap.put("listCountAll", list2);
		}
		mmap.put("lists", list);

		return prefix+"/goodsRecord";
	}

//	/**
//	 * 根据条件查询报表数据
//	 * @param request
//	 * @param purchasingUnitId
//	 * @param supplierId
//	 * @param beginDate
//	 * @param endDate
//	 * @return
//	 */
//	@RequestMapping(value = "searchByCondition", method = RequestMethod.POST)
//	public String searchByCondition(HttpServletRequest request,String beginDate, String endDate,String pageNum,String numPerPage){
//		if(null==request.getSession().getAttribute("userInfo")){
//			return "redirect:sessionOutNoResponseBody.action";
//		}
//		int currentPage = 1;
//		int pageSize = 20;
//		List<List<?>> listAll = procedureReportServiceImpl.searchAll(beginDate, endDate);
//		if(listAll.size() > 0 && listAll != null){
//			List listDetails = listAll.get(0);
//			List listCountAll = listAll.get(1);
//
//			if (pageNum != "" && pageNum != null && numPerPage != "" && numPerPage != null) {
//				currentPage = Integer.parseInt(pageNum);
//				pageSize = Integer.parseInt(numPerPage);
//			}
//
//			int beginRow = (currentPage - 1) * pageSize;
//			Pager pager = new Pager(pageSize,listDetails.size(),currentPage);
//			if(listDetails.size() > pageSize){
//				if(listDetails.size() > beginRow + pageSize){
//					pager.setDataList(listDetails.subList(beginRow, beginRow + pageSize));
//				}
//				else{
//					pager.setDataList(listDetails.subList(beginRow, listDetails.size()));
//				}
//			}
//			else{
//				pager.setDataList(listDetails);
//			}
//			request.setAttribute("pager", pager);
//			request.setAttribute("listCountAll", listCountAll);
//		}
//
//		request.setAttribute("beginDate", beginDate);
//		request.setAttribute("endDate", endDate);
//
//		return "report/searchAll";
//	}
//
//	/**
//	 * 事业单位供货统计
//	 * @param request
//	 * @param beginDate
//	 * @param endDate
//	 * @return
//	 */
//	@RequestMapping(value = "queryProvideRecord")
//	public String queryProvideRecord(HttpServletRequest request){
//		if(null==request.getSession().getAttribute("userInfo")){
//			return "redirect:sessionOutNoResponseBody.action";
//		}
//
//		// 初始页，每页显示20条数据
//		Map<String, Object> condition = new HashMap<String, Object>();
////		keywords
////		beginDate
////		endDate
////		beginRow
////		pageSize
//		List list = procedureReportServiceImpl.searchPageProvideRecord(condition);
//
//		Pager pager = new Pager(20,list.size(),1);
//		if(list.size() > 20){
//			pager.setDataList(list.subList(0, 20));
//		}
//		else{
//			pager.setDataList(list);
//		}
//		// 数据是查全部的
//
//
//		// 数据的汇总（总采购预算，总采购金额）
//		List list2 = procedureReportServiceImpl.sumProvideRecord(condition);
//
//		request.setAttribute("pager", pager);
//		request.setAttribute("listCountAll", list2);
//
//
//
////		List<List<?>> listAll = procedureReportServiceImpl.queryProvideRecord(null);
////		if(listAll != null && listAll.size() > 0){
////			List<Map> listDetails = (List<Map>) listAll.get(0);
////			List listCountAll = listAll.get(1);
////			int i = 0;
////			for(Map map : listDetails){
////				//取出项目编号中的汉字
////				String strProjectNumber = String.valueOf(map.get("projectNumber"));
////				if(!strProjectNumber.equals("") && strProjectNumber != null){
////					String[] tempProjectNumber = strProjectNumber.split("-");
////					int endIndex = 0;
////					for(int n = 0; n < tempProjectNumber[1].length(); n++){
////						if(!Character.isDigit(tempProjectNumber[1].charAt(n))){
////							endIndex = n;
////							break;
////						}
////					}
////					if(endIndex == 0){
////						endIndex = tempProjectNumber[1].length();
////					}
////					String projectNumber = tempProjectNumber[0].substring(tempProjectNumber[0].length() - 4, tempProjectNumber[0].length()) + "-" + tempProjectNumber[1].substring(0,endIndex);
////					map.put("projectNumber", projectNumber);
////				}
////
////				listDetails.set(i, map);
////				i++;
////			}
////
////			Pager pager = new Pager(20,listDetails.size(),1);
////			if(listDetails.size() > 20){
////				pager.setDataList(listDetails.subList(0, 20));
////			}
////			else{
////				pager.setDataList(listDetails);
////			}
////
////			request.setAttribute("pager", pager);
////			request.setAttribute("listCountAll", listCountAll);
////		}
//
//		return "report/provideRecord";
//	}
//
//	/**
//	 * 事业单位供货统计 分页
//	 * @param request
//	 * @param beginDate
//	 * @param endDate
//	 * @param keywords
//	 * @param pageNum
//	 * @param numPerPage
//	 * @return
//	 */
//	@RequestMapping(value = "queryProvideRecordPager", method = RequestMethod.POST)
//	public String queryProvideRecordPager(HttpServletRequest request,String beginDate, String endDate,String keywords,String pageNum,String numPerPage){
//		if(null==request.getSession().getAttribute("userInfo")){
//			return "redirect:sessionOutNoResponseBody.action";
//		}
//
//		Map<String, Object> condition = new HashMap<String, Object>();
//		if (keywords != null && !"".equals(keywords)) {
//			condition.put("keywords", keywords);
//		}
//		if((beginDate != null && !beginDate.equals("")) && (endDate != null && !endDate.equals(""))){
//			condition.put("beginDate", beginDate);
//			condition.put("endDate", endDate);
//		}
//
//		// 初始页，每页显示20条数据
////		Map<String, Object> condition = new HashMap<String, Object>();
////		keywords
////		beginDate
////		endDate
////		beginRow
////		pageSize
//		List list = procedureReportServiceImpl.searchPageProvideRecord(condition);
//
//		// 数据的汇总（总采购预算，总采购金额）
//		List list2 = procedureReportServiceImpl.sumProvideRecord(condition);
//
//		int currentPage = 1;
//		int pageSize = 20;
//		if (pageNum != "" && pageNum != null && numPerPage != "" && numPerPage != null) {
//			currentPage = Integer.parseInt(pageNum);
//			pageSize = Integer.parseInt(numPerPage);
//		}
//		int beginRow = (currentPage - 1) * pageSize;
//		Pager pager = new Pager(pageSize,list.size(),currentPage);
//		if(list.size() > pageSize){
//			if(list.size() > beginRow + pageSize){
//				pager.setDataList(list.subList(beginRow, beginRow + pageSize));
//			}
//			else{
//				pager.setDataList(list.subList(beginRow, list.size()));
//			}
//		}
//		else{
//			pager.setDataList(list);
//		}
//
//		request.setAttribute("pager", pager);
//		request.setAttribute("listCountAll", list2);
//
//
////		List<List<?>> listAll = procedureReportServiceImpl.queryProvideRecord(condition);
////		if(listAll != null && listAll.size() > 0){
////			List<Map> listDetails = (List<Map>) listAll.get(0);
////			List listCountAll = listAll.get(1);
////			int i = 0;
////			for(Map map : listDetails){
////				//取出项目编号中的汉字
////				String strProjectNumber = String.valueOf(map.get("projectNumber"));
////				String[] tempProjectNumber = strProjectNumber.split("-");
////				int endIndex = 0;
////				for(int n = 0; n < tempProjectNumber[1].length(); n++){
////					if(!Character.isDigit(tempProjectNumber[1].charAt(n))){
////						endIndex = n;
////						break;
////					}
////				}
////				if(endIndex == 0){
////					endIndex = tempProjectNumber[1].length();
////				}
////				String projectNumber = tempProjectNumber[0].substring(tempProjectNumber[0].length() - 4, tempProjectNumber[0].length()) + "-" + tempProjectNumber[1].substring(0,endIndex);
////				map.put("projectNumber", projectNumber);
//
////				String strSupplierName = String.valueOf(map.get("supplierName"));
////				if(strSupplierName.charAt(0) == ','){
////					strSupplierName = strSupplierName.substring(1, strSupplierName.length());
////				}
////				if(strSupplierName.charAt(strSupplierName.length() - 1) == ','){
////					strSupplierName = strSupplierName.substring(0, strSupplierName.length() - 1);
////				}
////				map.put("supplierName", strSupplierName);
////
////				String strGoodName = String.valueOf(map.get("goodName"));
////				if(strGoodName.charAt(0) == ','){
////					strGoodName = strGoodName.substring(1, strGoodName.length());
////				}
////				if(strGoodName.charAt(strGoodName.length() - 1) == ','){
////					strGoodName = strGoodName.substring(0, strGoodName.length() - 1);
////				}
////				map.put("goodName", strGoodName);
//
////				listDetails.set(i, map);
////				i++;
////			}
//
//
////		}
//		request.setAttribute("beginDate", beginDate);
//		request.setAttribute("endDate", endDate);
//		request.setAttribute("keywords", keywords);
//		return "report/provideRecord";
//	}
//	/**
//	 * 供货统计导出Excel
//	 * @param request
//	 * @param response
//	 * @param keywords
//	 * @param beginDate
//	 * @param endDate
//	 * @return
//	 */
//	@RequestMapping(value = "exportPorvideRecord")
//	public String exportPorvideRecord(HttpServletRequest request,HttpServletResponse response,String keywords,String beginDate,String endDate){
//		if(null==request.getSession().getAttribute("userInfo")){
//			return "redirect:sessionOutNoResponseBody.action";
//		}
//
//		Map<String, Object> condition = new HashMap<String, Object>();
//		if (keywords != null && !"".equals(keywords)) {
//			condition.put("keywords", keywords);
//		}
//		if((beginDate != null && !beginDate.equals("")) && (endDate != null && !endDate.equals(""))){
//			condition.put("beginDate", beginDate);
//			condition.put("endDate", endDate);
//		}
//
//		List<Map<String, Object>> listDetails = procedureReportServiceImpl.searchPageProvideRecord(condition);
//
//		// 数据的汇总（总采购预算，总采购金额）
//		List<Map<String, Object>> listCountAll = procedureReportServiceImpl.sumProvideRecord(condition);
//
//
//
////		List<List<?>> listAll = procedureReportServiceImpl.queryProvideRecord(condition);
//		if(listDetails != null && listDetails.size() > 0){
////			List<Map> listDetails = (List<Map>) listAll.get(0);
////			List<Map> listCountAll = (List<Map>) listAll.get(1);
////			int i = 0;
////			for(Map map : listDetails){
////				String strSupplierName = String.valueOf(map.get("supplierName"));
////				if(strSupplierName.charAt(0) == ','){
////					strSupplierName = strSupplierName.substring(1, strSupplierName.length());
////				}
////				if(strSupplierName.charAt(strSupplierName.length() - 1) == ','){
////					strSupplierName = strSupplierName.substring(0, strSupplierName.length() - 1);
////				}
////				map.put("supplierName", strSupplierName);
////
////				String strGoodName = String.valueOf(map.get("goodName"));
////				if(strGoodName.charAt(0) == ','){
////					strGoodName = strGoodName.substring(1, strGoodName.length());
////				}
////				if(strGoodName.charAt(strGoodName.length() - 1) == ','){
////					strGoodName = strGoodName.substring(0, strGoodName.length() - 1);
////				}
////				map.put("goodName", strGoodName);
////
////				listDetails.set(i, map);
////				i++;
////			}
//
//			//导出
//			try{
//				ServletOutputStream outputStream = response.getOutputStream();
//				String fileName = new String("安宁区行政事业单位协议供货统计明细表".getBytes(),"ISO8859_1");
//				String[] titles = {"单位名称","申请时间","项目编号","采购预算(元)","采购金额(元)","节约资金(元)","节约率(%)","物品名称","供应商"};
//				response.setHeader("Content-disposition", "attachment; filename=" + fileName + ".xlsx");// 组装附件名称和格式
//
//				XSSFWorkbook wb = new XSSFWorkbook();
//				XSSFSheet sheet = wb.createSheet("供货明细");
//				sheet.setColumnWidth(0, 4400);
//				sheet.setColumnWidth(1, 3000);
//				sheet.setColumnWidth(2, 2600);
//				sheet.setColumnWidth(3, 3600);
//				sheet.setColumnWidth(4, 3600);
//				sheet.setColumnWidth(5, 3600);
//				sheet.setColumnWidth(6, 2700);
//				sheet.setColumnWidth(7, 4500);
//				sheet.setColumnWidth(8, 6000);
//				//定义格式
//				XSSFCellStyle titleStyle = getTitleStyle(wb);
//				XSSFCellStyle conditionStyle = getConditionStyle(wb);
//				XSSFCellStyle headStyle = getHeadStyle(wb);
//				XSSFCellStyle bodayStyle = getBodyStyle(wb);
//				//表头
//				XSSFRow headRow = sheet.createRow(0);
//				headRow.setHeight((short)800);
//				XSSFRow headRow1 = sheet.createRow(1);
//				headRow1.setHeight((short)500);
//				XSSFRow headRow2 = sheet.createRow(2);
//				headRow2.setHeight((short)500);
//				XSSFCell cell = null;
//				for(int j = 0; j < titles.length; j++){
//					cell = headRow.createCell(j);
//					cell.setCellValue("");
//
//					cell = headRow1.createCell(j);
//					cell.setCellValue("");
//
//					cell = headRow2.createCell(j);
//					cell.setCellStyle(headStyle);
//					cell.setCellValue(titles[j]);
//				}
//				//标题栏
//				sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 8));
//				headRow.getCell(0).setCellStyle(titleStyle);
//				headRow.getCell(0).setCellValue("安宁区行政事业单位协议供货统计明细表");
//				//条件栏
//				sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 8));
//				headRow1.getCell(0).setCellStyle(conditionStyle);
//				if((beginDate != null && !beginDate.equals("")) && (endDate != null && !endDate.equals(""))){
//					headRow1.getCell(0).setCellValue("统计时间：从 " + beginDate + " 到 " + endDate + "                                                                        单位：元");
//				}
//				else{
//					headRow1.getCell(0).setCellValue("统计时间：                                                                                                单位：元");
//				}
//
//				//表体
//				if(listDetails.size() > 0 && listDetails != null){
//					int n = 3;
//					for(Map map : listDetails){
//						XSSFRow bodyRow = sheet.createRow(n);
//
//						cell = bodyRow.createCell(0);
//						cell.setCellStyle(bodayStyle);
//						cell.setCellValue(String.valueOf(map.get("unitName")));
//
//						cell = bodyRow.createCell(1);
//						cell.setCellStyle(bodayStyle);
//						cell.setCellValue(String.valueOf(map.get("createTime")));
//
//						cell = bodyRow.createCell(2);
//						cell.setCellStyle(bodayStyle);
//						cell.setCellValue(String.valueOf(map.get("projectNumber")));
//
//						cell = bodyRow.createCell(3);
//						cell.setCellStyle(bodayStyle);
//						cell.setCellValue(String.valueOf(map.get("em")));
//
//						cell = bodyRow.createCell(4);
//						cell.setCellStyle(bodayStyle);
//						cell.setCellValue(String.valueOf(map.get("dm")));
//
//						cell = bodyRow.createCell(5);
//						cell.setCellStyle(bodayStyle);
//						cell.setCellValue(String.valueOf(map.get("jyzj")));
//
//						cell = bodyRow.createCell(6);
//						cell.setCellStyle(bodayStyle);
//						cell.setCellValue(String.valueOf(map.get("jyl")));
//
//						cell = bodyRow.createCell(7);
//						cell.setCellStyle(bodayStyle);
//						cell.setCellValue(String.valueOf(map.get("goodName")));
//
//						cell = bodyRow.createCell(8);
//						cell.setCellStyle(bodayStyle);
//						cell.setCellValue(String.valueOf(map.get("supplierName")));
//
//						n++;
//					}
//					//最后一个行合计
//					XSSFRow lastRow = sheet.createRow(sheet.getPhysicalNumberOfRows());
//					for(Map map : listCountAll){
//						cell = lastRow.createCell(0);
//						cell.setCellStyle(bodayStyle);
//						cell.setCellValue(String.valueOf(""));
//
//						cell = lastRow.createCell(1);
//						cell.setCellStyle(bodayStyle);
//						cell.setCellValue(String.valueOf(""));
//
//						cell = lastRow.createCell(2);
//						cell.setCellStyle(bodayStyle);
//						cell.setCellValue(String.valueOf(""));
//
//						cell = lastRow.createCell(3);
//						cell.setCellStyle(bodayStyle);
//						cell.setCellValue(String.valueOf(map.get("zem")));
//
//						cell = lastRow.createCell(4);
//						cell.setCellStyle(bodayStyle);
//						cell.setCellValue(String.valueOf(map.get("zdm")));
//
//						cell = lastRow.createCell(5);
//						cell.setCellStyle(bodayStyle);
//						cell.setCellValue(String.valueOf(map.get("zjyzj")));
//
//						cell = lastRow.createCell(6);
//						cell.setCellStyle(bodayStyle);
//						cell.setCellValue(String.valueOf(map.get("zjyl")));
//
//						cell = lastRow.createCell(7);
//						cell.setCellStyle(bodayStyle);
//						cell.setCellValue(String.valueOf(""));
//
//						cell = lastRow.createCell(8);
//						cell.setCellStyle(bodayStyle);
//						cell.setCellValue(String.valueOf(""));
//					}
//					sheet.addMergedRegion(new CellRangeAddress(sheet.getPhysicalNumberOfRows() - 1, sheet.getPhysicalNumberOfRows() - 1, 0, 2));
//					lastRow.getCell(0).setCellStyle(headStyle);
//					lastRow.getCell(0).setCellValue("合计");
//				}
//
//				wb.write(outputStream);
//				outputStream.flush();
//				outputStream.close();
//			}
//			catch(IOException ex){
//				ex.printStackTrace();
//			}
//		}
//		return null;
//	}
//
//	/**
//     * 设置标题的单元格样式
//     *
//     * @return
//     */
//    private XSSFCellStyle getTitleStyle(XSSFWorkbook wb)
//    {
//        // 创建单元格样式
//        XSSFCellStyle cellStyle = wb.createCellStyle();
//        // 设置单元格的背景颜色为淡蓝色
////        cellStyle.setFillForegroundColor(HSSFColor.PALE_BLUE.index);
////        cellStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
//        // 设置单元格居中对齐
//        cellStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER);
//        // 设置单元格垂直居中对齐
//        cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
//        // 创建单元格内容显示不下时自动换行
//        cellStyle.setWrapText(true);
//        // 设置单元格字体样式
//        XSSFFont font = wb.createFont();
//        // 设置字体加粗
//        font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
//        font.setFontName("宋体");
//        font.setFontHeightInPoints((short)20);
//        cellStyle.setFont(font);
//        // 设置单元格边框为细线条
////        cellStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
////        cellStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
////        cellStyle.setBorderRight(XSSFCellStyle.BORDER_THIN);
////        cellStyle.setBorderTop(XSSFCellStyle.BORDER_THIN);
//        return cellStyle;
//    }
//    /**
//     * 设置条件栏的单元格样式
//     *
//     * @return
//     */
//    private XSSFCellStyle getConditionStyle(XSSFWorkbook wb)
//    {
//        // 创建单元格样式
//        XSSFCellStyle cellStyle = wb.createCellStyle();
//        // 设置单元格的背景颜色为淡蓝色
////        cellStyle.setFillForegroundColor(HSSFColor.PALE_BLUE.index);
////        cellStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
//        // 设置单元格居中对齐
//        cellStyle.setAlignment(XSSFCellStyle.ALIGN_LEFT);
//        // 设置单元格垂直居中对齐
//        cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
//        // 创建单元格内容显示不下时自动换行
//        cellStyle.setWrapText(true);
//        // 设置单元格字体样式
//        XSSFFont font = wb.createFont();
//        // 设置字体加粗
////        font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
//        font.setFontName("宋体");
//        font.setFontHeightInPoints((short)12);
//        cellStyle.setFont(font);
//        // 设置单元格边框为细线条
////        cellStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
////        cellStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
////        cellStyle.setBorderRight(XSSFCellStyle.BORDER_THIN);
////        cellStyle.setBorderTop(XSSFCellStyle.BORDER_THIN);
//        return cellStyle;
//    }
//	/**
//     * 设置表头的单元格样式
//     *
//     * @return
//     */
//    private XSSFCellStyle getHeadStyle(XSSFWorkbook wb)
//    {
//        // 创建单元格样式
//        XSSFCellStyle cellStyle = wb.createCellStyle();
//        // 设置单元格的背景颜色为淡蓝色
////        cellStyle.setFillForegroundColor(HSSFColor.PALE_BLUE.index);
////        cellStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
//        // 设置单元格居中对齐
//        cellStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER);
//        // 设置单元格垂直居中对齐
//        cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
//        // 创建单元格内容显示不下时自动换行
//        cellStyle.setWrapText(true);
//        // 设置单元格字体样式
//        XSSFFont font = wb.createFont();
//        // 设置字体加粗
////        font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
//        font.setFontName("宋体");
//        font.setFontHeightInPoints((short)12);
//        cellStyle.setFont(font);
//        // 设置单元格边框为细线条
//        cellStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
//        cellStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
//        cellStyle.setBorderRight(XSSFCellStyle.BORDER_THIN);
//        cellStyle.setBorderTop(XSSFCellStyle.BORDER_THIN);
//        return cellStyle;
//    }
//    /**
//     * 设置表体的单元格样式
//     *
//     * @return
//     */
//    private XSSFCellStyle getBodyStyle(XSSFWorkbook wb)
//    {
//        // 创建单元格样式
//        XSSFCellStyle cellStyle = wb.createCellStyle();
//        // 设置单元格左对齐
//        cellStyle.setAlignment(XSSFCellStyle.ALIGN_LEFT);
//        // 设置单元格垂直居中对齐
//        cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
//        // 创建单元格内容显示不下时自动换行
//        cellStyle.setWrapText(true);
//        // 设置单元格字体样式
//        XSSFFont font = wb.createFont();
//        // 设置字体加粗
////        font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
//        font.setFontName("宋体");
//        font.setFontHeightInPoints((short)11);
//        cellStyle.setFont(font);
//        // 设置单元格边框为细线条
//        cellStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
//        cellStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
//        cellStyle.setBorderRight(XSSFCellStyle.BORDER_THIN);
//        cellStyle.setBorderTop(XSSFCellStyle.BORDER_THIN);
//        return cellStyle;
//    }
//
//	@ResponseBody
//	@RequestMapping(value="sessionOutNoResponseBody")
//	public String sessionOutNoResponseBody(HttpSession session){
//
//		return DwrJson.toJson("301", "会话超时，请重新登录!","", "","","");
//
//	}
//
//
//
//	/**
//	 * 新添加功能--按照分类查询购买货物
//	 * @param request
//	 * @param beginDate
//	 * @param endDate
//	 * @return
//	 */
//	@RequestMapping(value = "queryClassificationGoodsRecord")
//	public String queryClassificationGoodsRecord(HttpServletRequest request,String keywords,String pageNum,String numPerPage){
//		if(null==request.getSession().getAttribute("userInfo")){
//			return "redirect:sessionOutNoResponseBody.action";
//		}
//
//		request.setAttribute("keywords", keywords);
//
//		Map<String, Object> condition = new HashMap<String, Object>();
//
//		if(keywords!= null && (keywords.contains("本") || keywords.contains("笔") || keywords.contains("记"))){
//			condition.put("keywords", "笔记本");
//			condition.put("keywords2", "便携式计算机");
//		}else if(keywords!= null && keywords.contains("便携式计算机")){
//			condition.put("keywords", "笔记本");
//			condition.put("keywords2", "便携式计算机");
//		}else if(keywords!= null && (keywords.contains("u") || keywords.contains("U") || keywords.contains("优") )){
//			condition.put("keywords", "u");
//			condition.put("keywords2", "优");
//		}else if(keywords!= null && (keywords.contains("电脑"))){
//			condition.put("keywords", keywords);
//			condition.put("keywords2", keywords.replace("电脑", "计算机"));
//		}else if(keywords!= null && (keywords.contains("计算机"))){
//			condition.put("keywords", keywords);
//			condition.put("keywords2", keywords.replace("计算机", "电脑"));
//		}
//		else if(keywords!= null){
//			condition.put("keywords", keywords);
//			condition.put("keywords2", null);
//		}
//		// 计算页码，页面的数据大小
////		int ipageNum =1;
////		int inumPerPage=20;
////		try{
////			ipageNum = Integer.parseInt(pageNum);
////		}catch(Exception e){
////			ipageNum=1;
////		}
////		try{
////			inumPerPage = Integer.parseInt(numPerPage);
////		}catch(Exception e){
////			inumPerPage=20;
////		}
////		condition.put("beginRow",(ipageNum - 1) * inumPerPage);
////		condition.put("pageSize", inumPerPage);
//
//		// 初始页，每页显示20条数据
//		List list = procedureReportServiceImpl.queryClassificationGoodsRecord(condition);
//
//		int currentPage = 1;
//		int pageSize = 20;
//		if (pageNum != "" && pageNum != null && numPerPage != "" && numPerPage != null) {
//			currentPage = Integer.parseInt(pageNum);
//			pageSize = Integer.parseInt(numPerPage);
//		}
//		int beginRow = (currentPage - 1) * pageSize;
//		Pager pager = new Pager(pageSize,list.size(),currentPage);
//		if(list.size() > pageSize){
//			if(list.size() > beginRow + pageSize){
//				pager.setDataList(list.subList(beginRow, beginRow + pageSize));
//			}
//			else{
//				pager.setDataList(list.subList(beginRow, list.size()));
//			}
//		}
//		else{
//			pager.setDataList(list);
//		}
//
//		//Integer pageSize, Integer totalCount,Integer currentPage
////		Pager pager = new Pager(inumPerPage,list.size(),ipageNum);
////		if(list.size() > inumPerPage){
////			pager.setDataList(list.subList(0, inumPerPage));
////		}
////		else{
////			pager.setDataList(list);
////		}
//		// 数据是查全部的
//
//		if(list.size()<=1){
//			List list2 = new ArrayList();
//			Map<String, Object> map = new HashMap<String, Object>();
//			map.put("sumNumber", 0);
//			map.put("sumAmount", 0);
//			list2.add(map);
//			request.setAttribute("listCountAll", list2);
//
//		}else{
//		// 数据的汇总（总采购预算，总采购金额）
//		List list2 = procedureReportServiceImpl.sumClassificationGoodsRecord(condition);
//		request.setAttribute("listCountAll", list2);
//		}
//		request.setAttribute("pager", pager);
//
//		return "classificationGoods/goodsRecord";
//	}
//
//	/**
//	 * 新添加功能--按照分类查询购买货物
//	 * @param request
//	 * @param beginDate
//	 * @param endDate
//	 * @return
//	 */
//	@RequestMapping(value = "exportClassificationGoodsRecord",method=RequestMethod.POST)
//	public String exportClassificationGoodsRecord(HttpServletRequest request,HttpServletResponse response,String keywords){
//		if(null==request.getSession().getAttribute("userInfo")){
//			return "redirect:sessionOutNoResponseBody.action";
//		}
//
//		//request.setAttribute("keywords", keywords);
//
//		Map<String, Object> condition = new HashMap<String, Object>();
//
//		if(keywords!= null && (keywords.contains("本") || keywords.contains("笔") || keywords.contains("记"))){
//			condition.put("keywords", "笔记本");
//			condition.put("keywords2", "便携式计算机");
//		}else if(keywords!= null && keywords.contains("便携式计算机")){
//			condition.put("keywords", "笔记本");
//			condition.put("keywords2", "便携式计算机");
//		}else if(keywords!= null && (keywords.contains("u") || keywords.contains("U") || keywords.contains("优") )){
//			condition.put("keywords", "u");
//			condition.put("keywords2", "优");
//		}else if(keywords!= null && (keywords.contains("电脑"))){
//			condition.put("keywords", keywords);
//			condition.put("keywords2", keywords.replace("电脑", "计算机"));
//		}else if(keywords!= null && (keywords.contains("计算机"))){
//			condition.put("keywords", keywords);
//			condition.put("keywords2", keywords.replace("计算机", "电脑"));
//		}else if(keywords!= null){
//			condition.put("keywords", keywords);
//			condition.put("keywords2", null);
//		}
//
//		// 初始页，每页显示20条数据
//		List<Map<String, Object>> list = procedureReportServiceImpl.queryClassificationGoodsRecord(condition);
//		List<Map<String, Object>> countAll = null;
//		System.out.println(list.size()+"===================");
//		if(list.size()<=1){
//			List list2 = new ArrayList();
//			Map<String, Object> map = new HashMap<String, Object>();
//			map.put("sumNumber", 0);
//			map.put("sumAmount", 0);
//			list2.add(map);
//			countAll = list2;
//
//		}else{
//			// 数据的汇总（总采购预算，总采购金额）
//			List<Map<String, Object>> list2 = procedureReportServiceImpl.sumClassificationGoodsRecord(condition);
//			countAll = list2;
//		}
//
//		// 写入excel表中
//
//
//
//		//导出
//		try{
//			ServletOutputStream outputStream = response.getOutputStream();
//			String fileName = new String("安宁区行政事业单位协议供货分类统计表".getBytes(),"ISO8859_1");
//			String[] titles = {"项目编号","采购单位名称","采购物品名称","数量","成交价格(元)","采购金额(元)","供应商","日期"};
//			response.setHeader("Content-disposition", "attachment; filename=" + fileName + ".xlsx");// 组装附件名称和格式
//
//			XSSFWorkbook wb = new XSSFWorkbook();
//			XSSFSheet sheet = wb.createSheet("分类统计");
//			sheet.setColumnWidth(0, 4400);
//			sheet.setColumnWidth(1, 6000);
//			sheet.setColumnWidth(2, 6600);
//			sheet.setColumnWidth(3, 3600);
//			sheet.setColumnWidth(4, 3600);
//			sheet.setColumnWidth(5, 3600);
//			sheet.setColumnWidth(6, 6700);
//			sheet.setColumnWidth(7, 4500);
//			//定义格式
//			XSSFCellStyle titleStyle = getTitleStyle(wb);
//			XSSFCellStyle conditionStyle = getConditionStyle(wb);
//			XSSFCellStyle headStyle = getHeadStyle(wb);
//			XSSFCellStyle bodayStyle = getBodyStyle(wb);
//			//表头
//			XSSFRow headRow = sheet.createRow(0);
//			headRow.setHeight((short)800);
//			XSSFRow headRow1 = sheet.createRow(1);
//			headRow1.setHeight((short)500);
//			XSSFRow headRow2 = sheet.createRow(2);
//			headRow2.setHeight((short)500);
//			XSSFCell cell = null;
//			for(int j = 0; j < titles.length; j++){
//				cell = headRow.createCell(j);
//				cell.setCellValue("");
//
//				cell = headRow1.createCell(j);
//				cell.setCellValue("");
//
//				cell = headRow2.createCell(j);
//				cell.setCellStyle(headStyle);
//				cell.setCellValue(titles[j]);
//			}
//			//标题栏
//			sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 7));
//			headRow.getCell(0).setCellStyle(titleStyle);
//			headRow.getCell(0).setCellValue("安宁区行政事业单位协议供货分类统计表");
//			//条件栏
//			sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 7));
//			headRow1.getCell(0).setCellStyle(conditionStyle);
//
//			//表体
//			if(list.size() > 0 && list != null){
//				int n = 3;
//				for(Map map:list){
//					XSSFRow bodyRow = sheet.createRow(n);
//
//					cell = bodyRow.createCell(0);
//					cell.setCellStyle(bodayStyle);
//					cell.setCellValue(String.valueOf(map.get("unitNumber")));
//
//					cell = bodyRow.createCell(1);
//					cell.setCellStyle(bodayStyle);
//					cell.setCellValue(String.valueOf(map.get("unitName")));
//
//					cell = bodyRow.createCell(2);
//					cell.setCellStyle(bodayStyle);
//					cell.setCellValue(String.valueOf(map.get("items")));
//
//					cell = bodyRow.createCell(3);
//					cell.setCellStyle(bodayStyle);
//					cell.setCellValue(String.valueOf(map.get("number")));
//
//					cell = bodyRow.createCell(4);
//					cell.setCellStyle(bodayStyle);
//					cell.setCellValue(String.valueOf(map.get("price")));
//
//					cell = bodyRow.createCell(5);
//					cell.setCellStyle(bodayStyle);
//					cell.setCellValue(String.valueOf(map.get("amount")));
//
//					cell = bodyRow.createCell(6);
//					cell.setCellStyle(bodayStyle);
//					cell.setCellValue(String.valueOf(map.get("supplierName")));
//
//					cell = bodyRow.createCell(7);
//					cell.setCellStyle(bodayStyle);
//					cell.setCellValue(String.valueOf(map.get("createTime")));
//
//					n++;
//				}
//				//最后一个行合计
//				XSSFRow lastRow = sheet.createRow(sheet.getPhysicalNumberOfRows());
//				for(Map map : countAll){
//					cell = lastRow.createCell(0);
//					cell.setCellStyle(bodayStyle);
//					cell.setCellValue(String.valueOf(""));
//
//					cell = lastRow.createCell(1);
//					cell.setCellStyle(bodayStyle);
//					cell.setCellValue(String.valueOf(""));
//
//					cell = lastRow.createCell(2);
//					cell.setCellStyle(bodayStyle);
//					cell.setCellValue(String.valueOf(""));
//
//					cell = lastRow.createCell(3);
//					cell.setCellStyle(bodayStyle);
//					cell.setCellValue(String.valueOf(map.get("sumNumber")));
//
//					cell = lastRow.createCell(4);
//					cell.setCellStyle(bodayStyle);
//					cell.setCellValue(String.valueOf(""));
//
//					cell = lastRow.createCell(5);
//					cell.setCellStyle(bodayStyle);
//					cell.setCellValue(String.valueOf(map.get("sumAmount")));
//
//					cell = lastRow.createCell(6);
//					cell.setCellStyle(bodayStyle);
//					cell.setCellValue(String.valueOf(""));
//
//					cell = lastRow.createCell(7);
//					cell.setCellStyle(bodayStyle);
//					cell.setCellValue(String.valueOf(""));
//
//				}
//				sheet.addMergedRegion(new CellRangeAddress(sheet.getPhysicalNumberOfRows() - 1, sheet.getPhysicalNumberOfRows() - 1, 0, 2));
//				lastRow.getCell(0).setCellStyle(headStyle);
//				lastRow.getCell(0).setCellValue("合计");
//			}
//
//			wb.write(outputStream);
//			outputStream.flush();
//			outputStream.close();
//		}
//		catch(IOException ex){
//			ex.printStackTrace();
//		}
//
//		return null;
//	}
//
	
}
